package org.timemachine.factory;

import java.lang.reflect.Field;
import java.util.Date;

import org.timemachine.context.TMThreadLocal;
import org.timemachine.model.base.ChangeInfo;

public class ChangeInfoFactory {
	
	public static ChangeInfo getNewInstance() {
		ChangeInfo changeInfo = new ChangeInfo();
		changeInfo.setChangeTimeStamp(new Date());
		Class<?> c = changeInfo.getClass();
		
		try {
			for (String key : TMThreadLocal.getContext().getKeySet()) {

				Field chap = c.getDeclaredField(key);
				chap.setAccessible(true);

				chap.set(changeInfo, TMThreadLocal.getContext().get(key));

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return changeInfo;
	}

}
